package terra.network.packet.server;

import org.jboss.netty.buffer.ChannelBuffer;

import terra.network.packet.Packet;


public class CraftResult extends Packet {

	public final static int COUNT = 9;
	public final static byte SUCCESS = 1;
	public final static int FAIL = 0;
	public int playerId;
	public byte craftResult;
	public int itemOids[] = new int[COUNT];
	public int itemIds[] = new int[COUNT];
	public int itemCounts[] = new int[COUNT];
	
	public CraftResult(int playerId) {
		this.playerId = playerId;
	}

	public CraftResult() {
	}

	@Override
	public ChannelBuffer toBuffer() {
		ChannelBuffer buf = getNewBuffer();
		buf.writeByte(getId());
		buf.writeInt(playerId);
		buf.writeByte(craftResult);
		for(int i = 0; i < COUNT;i++){
			buf.writeInt(itemOids[i]);
			buf.writeInt(itemIds[i]);
			buf.writeInt(itemCounts[i]);
		}
		return buf;
	}

	@Override
	public Packet fromBuffer(ChannelBuffer buf) {
		playerId = buf.readInt();
		craftResult = buf.readByte();
		for(int i = 0; i < COUNT;i++){
			itemOids[i] = buf.readInt();
			itemIds[i] = buf.readInt();
			itemCounts[i] = buf.readInt();
		}
		return this;
	}

	@Override
	public int getLength() {
		return 5+109;
	}

	@Override
	public boolean isDynamicLength() {
		return false;
	}

	@Override
	public byte getId() {
		return 27;
	}
	
	@Override
	public byte getPriority() {
		return PRIOR_NORMAL;
	}

}
